package com.clms.rents.service.impl;

import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.clms.common.R;
import com.clms.rents.mapper.TabCarType;
import com.clms.rents.pojo.entity.TbCar;
import com.clms.rents.pojo.entity.TbCarType;
import com.clms.rents.pojo.vo.CarTypeVo;
import com.clms.rents.service.CarTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: clms-third
 * @description: 车的类型（高端，低端）业务层
 * @author: 杨浩
 * @create: 2021-07-22 12:06
 **/
@Service
public class CarTypeServiceimpl implements CarTypeService {

    @Resource
    private TabCarType tabCarType;

    @Override
    public R selectall() {
        List<TbCarType> tbCarTypes = tabCarType.selectList(null);
        return R.ok().put("allCarTypes",tbCarTypes);

    }

    @Override
    public R pageSelect(Integer currentPage, Integer pageSize, CarTypeVo carTypeVo) {
        Page<TbCarType> page=new Page<>(currentPage,pageSize);
        QueryWrapper<TbCarType> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(carTypeVo.getTypeName())){
            queryWrapper.like("type_name",carTypeVo.getTypeName());
        }
        Page<TbCarType> page1 = tabCarType.selectPage(page, queryWrapper);
        return R.ok().put("total",page1.getTotal()).put("records",page1.getRecords());

    }

    @Override
    public R insert(TbCarType tbCarType) {
        int insert = tabCarType.insert(tbCarType);
        return R.ok();

    }

    @Override
    public R update(TbCarType tbCarType) {
        int update = tabCarType.updateById(tbCarType);
        return R.ok();

    }

    @Override
    public R selectById(Integer id) {
        TbCarType tbCarType = tabCarType.selectById(id);
        return R.ok().put("huixian",tbCarType);

    }

    @Override
    public R delete(Integer id) {
        int i = tabCarType.deleteById(id);
        return R.ok();

    }


}
